const state = {
  dictDataList: [],    // 字典数据集合
  dictDataMap: new Map(),  // 字典数据map，key为dictType，value为list dictData
  dictTypeList: [],    // 字典类型集合
  dictTypeMap: new Map(),  // 字典类型map，key为code，value为 ob
  systemProperties: new Map()  // 字典类型map，key为code，value为 ob
}

const getters = {
  dictDataList: state => state.dictDataList,
  dictDataMap: state => state.dictDataMap,
  dictTypeList: state => state.dictTypeList,
  dictTypeMap: state => state.dictTypeMap,
  systemProperties: state => state.systemProperties,
}

const mutations = {
  setDictDataList: (state, list) => {
    state.dictDataList = list

    let map = new Map()
    list.forEach(o => {
      let key = o.dictTypeCode
      let dictList = map.get(key)
      if (dictList === undefined || dictList === null) {
        dictList = []
      }
      dictList.push(o)
      map.set(key, dictList)
    })
    state.dictDataMap = map
  },
  setDictTypeList: (state, list) => {
    state.dictTypeList = list

    let map = new Map()
    list.forEach(o => {
      map.set(o.code, o)
    })
    state.dictTypeMap = map
  },
  setSystemProperties: (state, systemProperties) => {
    state.systemProperties = systemProperties
  }
}

const actions = {
  setDictDataList: (context, list) => context.commit('setDictDataList', list),
  setDictTypeList: (context, list) => context.commit('setDictTypeList', list),
  setSystemProperties: (context, systemProperties) => context.commit('setSystemProperties', systemProperties),
}

export default {
  state,
  getters,
  mutations,
  actions
}
